<?php
require_once ('../config/path_config.php');
require_once(ROOTDIR."admin/admin-header.php");
require_once(ROOTDIR."common/db_utils.php");
require_once("../include/check_get_key.php");

// 获取题目信息
$id=intval($_GET['id']);
$sql="SELECT `defunct`, `creater_id` FROM `problem` WHERE `problem_id`=?";
$result = DbUtil::getInstance()->query($sql, $id);
$row=$result[0];
$defunct=$row['defunct'];
$createrId=$row['creater_id'];

$allowAccess = isset($_SESSION['administrator']);
if ( !$allowAccess ) {
    $allowAccess = isset($_SESSION['problem_editor'])
        && strtolower($createrId) == strtolower($_SESSION['user_id']);
}
if ( !$allowAccess ){
    echo "不具备访问该页面的权限";
    exit(1);
}

// 修改题目状态
if ($defunct=='Y') {
    $sql="update `problem` set `defunct`='N' where `problem_id`=?";
}
else {
    $sql="update `problem` set `defunct`='Y' where `problem_id`=?";
}
DbUtil::getInstance()->query($sql,$id);

?>
<script language=javascript>
	history.go(-1);
</script>